package org.xw.controller;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import org.xw.pojo.ChatPojo;
import org.xw.pojo.MembersPojo;
import org.xw.service.ChatService;
import org.xw.utils.ResponseUtil;

import java.util.List;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Resource
    ChatService chatService;

    /**
     * 创建群聊（双人或多人）
     */
    @PostMapping("/create")
    public ResponseUtil create(HttpServletRequest httpServletRequest,@RequestBody ChatPojo chat) {
        return chatService.create(httpServletRequest,chat);
    }

    /**
     * 拉人进群
     */
    @PutMapping("/pull")
    public ResponseUtil Pull(HttpServletRequest httpServletRequest,@RequestBody List<MembersPojo> membersPojo) {
        return chatService.Pull(httpServletRequest, membersPojo);
    }

    /**
     * 查询群聊
     */
    @GetMapping("")
    public ResponseUtil getChatById(HttpServletRequest httpServletRequest, Integer chatId) {
        return chatService.getChatById(httpServletRequest, chatId);
    }

    /**
     * 踢人
     */
    @PostMapping("/out")
    public ResponseUtil out(HttpServletRequest httpServletRequest,@RequestBody List<MembersPojo> membersPojo) {
        return chatService.out(httpServletRequest, membersPojo);
    }

    /**
     * 解散群聊
     */
    @PostMapping("/dissolve")
    public ResponseUtil dissolve(HttpServletRequest httpServletRequest, Integer chatId) {
        return chatService.dissolve(httpServletRequest, chatId);
    }

    /**
     * 退群
     *
     * @param httpServletRequest
     * @param chatId
     * @return
     */
    @PostMapping("/quit")
    public ResponseUtil quit(HttpServletRequest httpServletRequest, Integer chatId) {
        return chatService.quit(httpServletRequest, chatId);
    }

    /**
     * 置顶群聊
     *
     * @param httpServletRequest
     * @param chatId
     * @return
     */
    @PutMapping("/top")
    public ResponseUtil top(HttpServletRequest httpServletRequest, Integer chatId) {
        System.out.println(httpServletRequest);
        System.out.println(chatId);
        return chatService.top(httpServletRequest, chatId);
    }


    /**
     * 更新群名称、图片
     *
     * @param httpServletRequest
     * @param chatPojo
     * @return
     */
    @PostMapping("/updatedata")
    public ResponseUtil update(HttpServletRequest httpServletRequest,@RequestBody ChatPojo chatPojo) {
        return chatService.update(httpServletRequest, chatPojo);
    }

    /**
     * 查询个人所有群聊
     * @param httpServletRequest
     * @return
     */
    @GetMapping("/chatlist")
    public ResponseUtil getChatList(HttpServletRequest httpServletRequest){
        return chatService.getChatList(httpServletRequest);
    }


}
